/*
 * SeparateColumnDateFormat.java
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 * 
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 * 
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package vegadataeditor.DateFormatClasses;

import java.util.Date;
import java.util.Calendar;

/**
 * Format the date as year,month,day,hour,minute,second with supplied delimiter.
 * @author lawinslow
 */
public class SeparateColumnDateFormat implements IDateFormatter{
    private String delim;
    private Calendar cal;

    /**
     * Constructor using default delimiter (comma).
     */
    public SeparateColumnDateFormat(){
        this(",");
    }
    /**
     * Constructor allowing you to supply a custom delimiter.
     *
     * @param delimiter Delimiter to separate fields
     */
    public SeparateColumnDateFormat(String delimiter){
        delim = delimiter;
        cal = Calendar.getInstance();
    }

    /**
     * Format the date as year,month,day,hour,minute,second with supplied delimiter.
     * No hanging delimiter on end.
     *
     * @param d date to return formatted as string
     * @return String with year, month,... separated by delimiter. No delimiter on end.
     */
    public String format(Date d) {
        cal.setTime(d);
        return cal.get(Calendar.YEAR)+delim+(cal.get(Calendar.MONTH)+1)+
                delim+cal.get(Calendar.DAY_OF_MONTH)+delim+
                cal.get(Calendar.HOUR_OF_DAY)+delim+cal.get(Calendar.MINUTE)+
                delim+cal.get(Calendar.SECOND);
    }

    public String getHeader() {
        return "Year"+delim+"Month"+delim+"Day"+
                delim+"Hour"+delim+"Minute"+delim+"Second";
    }


}
